﻿// ReSharper disable InconsistentNaming
using System;
using System.Linq;
using NEasy.Ldap;
using NEasyLdap.Tests.Entity;
using NUnit.Framework;

namespace NEasyLdap.Tests.BasicAccessTests
{
    [TestFixture()]
    public class Read_User_Information_
    {
        private LdapRepository sut;

        [SetUp()]
        public void Setup()
        {
            Console.WriteLine();

            sut = new LdapRepository(
                new LdapDomainInfo("mentzel.org", "CN=Users,DC=Mentzel,DC=org"));
        }

        [TearDown()]
        public void TearDown()
        {
        }

        [Test()]
        public void Change_SAMAccount()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "Test" });
            person.SAMAccountName = "TestChange";
            sut.Update(person);
        }

        [Test()]
        public void Change_Comment()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "Test" });
            person.Comment = "TestChange";
            sut.Update(person);
        }

        [Test()]
        public void Get_Groups()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "Administrator" });

            var groups = person.GetGroups();
            Assert.That(groups.Count(), Is.GreaterThan(0));

            foreach (var ldapGroupBase in groups)
            {
                Console.WriteLine(ldapGroupBase.CanonicalName);
            }
        }
    }
}
